<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('仓库设置')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            仓库编码：<input type="text" name="wareCode"/>
                        </li>

                        <li>
                            仓库名称：<input type="text" name="wareName"/>
                        </li>

                        <li>
                            仓库类型：<select name="type">
                            <option value="">全部</option>
                            <option value="1">立体</option>
                            <option value="2">平仓</option>
                            <option value="3">地堆</option>
                        </select>
                        </li>

                        <li>
                            仓库环境：<select name="wareEv">
                            <option value="">全部</option>
                            <option value="1">常温</option>
                            <option value="2">冷冻</option>
                            <option value="3">冷藏</option>
                            <option value="4">防爆</option>
                            <option value="5">阴凉</option>
                        </select>
                        </li>


                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="btn-group-sm" id="toolbar" role="group">

            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:wareInfo:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()"
               shiro:hasPermission="system:wareInfo:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger btn-del disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="system:wareInfo:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:wareInfo:export">
                <i class="fa fa-download"></i> 导出
            </a>
            <a class="btn btn-primary" onclick="$.table.print()">
                <i class="fa fa-plus"></i> 打印
            </a>
            <a class="btn btn-info btn-lg " onclick="bit()"><!--shiro:hasPermission="basics:purchase:bit"-->
                <i class="fa fa-500px"></i> 生成二维码
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true" style="white-space: nowrap"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>

<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:wareInfo:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:wareInfo:remove')}]];
    var prefix = ctx + "system/wareInfo";
    var sleep = function(time) {
        var startTime = new Date().getTime() + parseInt(time, 10);
        while(new Date().getTime() < startTime) {}
    };




    function bit() {


        var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);

        var split = rows.toString().split(",");

        if(split==''){
           $.modal.alert("请选择数据")
        }else{
            for (var i=0; i<split.length; i++)
            {
                window.location.href="http://localhost:8000/system/wareInfo/qr?ids="+split[i]+""
                sleep(1500)

            }
        }







       /* $.ajax({
            url: "http://localhost:8000/system/wareInfo/qr",
            data: {ids: rows.toString()},
            responseType: 'ms-stream',
            success: function f(data) {


                const url = window.URL.createObjectURL(new Blob([data], {type: "image/png"}))
                const link = document.createElement('a')
                link.style.display = 'none'
                link.href = url
                link.setAttribute('download', '1.png')
                document.body.appendChild(link)
                link.click()
                document.body.removeChild(link)




            }

        });*/


    }

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "仓库数据",
            showExport: false,
            columns: [
                {
                    checkbox: true
                },
                {
                    field: 'wareId',
                    title: '仓库ID',
                    align: 'center',
                    visible: false
                },
                {
                    field: 'wareCode',
                    title: '仓库编码',
                    align: 'center',
                    visible: true
                },
                {
                    field: 'wareName',
                    title: '仓库名称',
                    align: 'center',
                    visible: true
                },
                {
                    field: 'type',
                    title: '仓库类型',
                    align: 'center',
                    visible: true,
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return "立体";
                        } else if (value == 2) {
                            return "平仓";
                        } else if (value == 3) {
                            return "地堆";
                        }
                    }
                },
                {
                    field: 'wareEv',
                    title: '仓库环境',
                    align: 'center',
                    visible: true,
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return "常温";
                        } else if (value == 2) {
                            return "冷冻";
                        } else if (value == 3) {
                            return "冷藏";
                        } else if (value == 4) {
                            return "防爆";
                        } else if (value == 5) {
                            return "阴凉";
                        }
                    }
                },
                {
                    field: 'memo',
                    title: '备注',
                    align: 'center',
                    visible: true
                },
                // {
                //     field: 'expectedWaring',
                //     title: '爆仓预警',
                //     align: 'center',
                //     visible: true,
                //     formatter: function(value, row, index){
                //         if(value != null){
                //             return value + "%";
                //         }
                //     }
                // },
                // {
                //     field: 'alarm',
                //     title: '爆仓报警',
                //     align: 'center',
                //     visible: true,
                //     formatter: function(value, row, index){
                //         if(value != null){
                //             return value + "%";
                //         }
                //     }
                // },
                // {
                //     field: 'boxParam',
                //     title: '物料数量在框中占比上限',
                //     align: 'center',
                //     visible: true,
                //     formatter: function(value, row, index){
                //         if(value != null){
                //             return value + "%";
                //         }
                //     }
                // },
                // {
                //     field: 'boxHeight',
                //     title: '单箱可储存高度（毫米）',
                //     align: 'center',
                //     visible: true
                // },
                // {
                //     field: 'unqualifiedStorageDay',
                //     title: '不合格物料存储天数（天）',
                //     align: 'center',
                //     visible: true
                // },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.wareId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.wareId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }
            ]
        };
        $.table.init(options);
    });

    var app = new Vue({
        el: '.container-div',
        data: {
            wares: [],
        },
        methods: {
            getWares: function () {
                var that = this;
                $.ajax({
                    cache: true,
                    type: "POST",
                    url: "/system/wareInfo/list",
                    data: {},
                    async: false,
                    error: function (request) {
                        $.modal.alertError("系统错误");
                    },
                    success: function (data) {
                        that.wares = data.rows;
                    }
                });
            }
        },
        created() {
            this.getWares();
        }
    })
</script>
</body>
</html>
